Variables
Variables are temporary storage areas to which you can assign values which you can use later in your scripts.
If a variable is referred to and it doesn't exist, it returns the value $null. The $null value can be used in comparisons in if-then-else statements to control branching etc.
The following commands allow you to create and set the values of variables.
/set [-snzekuN] <%var> [value] This sets the value of %var to the specified value.
If you specify the -uN switch, %var is unset after N seconds, assuming it is not set again by another script. If you specify a zero for N, the variable is unset when the script finishes.
The -k switch keeps the current -uN setting for a variable. The -n switch makes it treat value as plain text. The -z switch decreases %var until it reaches zero and then unsets it. The -e switch unsets the variable when mIRC exits.
This unsets and removes the specified variables from the variables list. If you specify a variable with wildcard characters then all matching variables will be removed.
/unset %test*
This will remove all variables beginning with the word %test.
You can also set/unset dynamic variables using [] brackets:
vartest { set %a [ $+ b ] 1 set %a [ $+ c ] 2 set %a [ $+ d ] 3
echo ab = %ab echo ac = %ac echo ad = %ad
unset %a [ $+ b ] %a [ $+ c ] %a [ $+ d ] }
This unsets and removes all variables from the variables list.
This increases the value of %var by value.
If you specify the -uN switch, %var is increased by the value once and then %var is unset N seconds later, assuming it is not set again by another script.
The -c switch increases %var once per second. The -z switch decreases %var until it reaches zero and then unsets it. The -e switch unsets the variable when mIRC exits.
This decreases the value of %var by value.
If you specify the -uN switch, %var is decreased by the value once and then %var is unset N seconds later, assuming it is not set again by another script.
The -c switch decreases %var once per second. The -z switch decreases %var until it reaches zero and then unsets it. The -e switch unsets the variable when mIRC exits.
You can also use the equal sign to assign values to variables:
%i = 5 %xyzi = 3.14159 %count = $1
And you can perform the following operations on variables when using the equal sign:
%x = 5 + 1 %x = 5 - %y %x = %x * 2 %x = %z / $2 %x = $1 % 3 %x = 2 ^ %w
You can only perform a single operation in an assignment at this time.
You can also use the $calc() identifier which allows you to perform complex calculations.
//echo 1 $calc(3.14159 * (2 ^ %x % 3) - ($ticks / (10000 + 1)))
For floating point numbers you can also use the $round(N,D) and $int(N) identifiers to handle precision of the decimal digits. The number of decimals is currently limited to 5 digits.
Local variables are variables that exist only for the duration of the script in which they are created and can only be accessed from within that script. They can be created with the /var command:
/var %x
This creates the local variable %x in the current routine and can only be referenced from inside this routine.
/var %x = hello
This creates a local variable %x and assigns it the value hello.
You can create multiple local variables by separating them with commas:
/var %x = hello, %y, %z = $me
loop { var %x = 1 :next echo item %x inc %x if (%x < 10) goto next }
Note: You can use /var -s to make a variable show the result when a value is set, and /var -g to set a global variable.
Identifiers
Returns the Nth matching variable name.
Properties: value, local, secs
You can use a wildcard in the variable name.
If N = 0, returns total number of matching variable names.
Note: This searches both local and global variables. |